package com.zbec.mdrs.repository.jpa;


import com.zbec.mdrs.entity.report.ReportTask;
import com.zbec.mdrs.vo.ReportTaskVo;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.PagingAndSortingRepository;
import org.springframework.data.repository.query.Param;

import java.util.List;

/**
 * Created by fxl on 2015/10/17.
 */
public interface ReportTaskDao extends PagingAndSortingRepository<ReportTask, Long>, JpaSpecificationExecutor<ReportTask> {

    @Query("select t  from ReportTask t where YEAR(t.businessMonth)=:year and MONTH(t.businessMonth)=:month and t.businessType=:bizType and t.status <>:status ")
    List<ReportTask> findActiveReportTaskByYwMonthAndBizType(@Param("year")Integer year , @Param("month")Integer month, @Param("bizType")String bizType,@Param("status")String status);

    @Query("select new com.zbec.mdrs.vo.ReportTaskVo(t.id,t.businessType,t.businessMonth,t.reportTimes,t.status)" +
            " from ReportTask t " +
            " order by t.id desc")
    Page<ReportTaskVo> findAllTask( Pageable pageable);
}
